function [event_clock,alg]=repair(event_clock,alg)


global NUMBER_OF_EVENTS LENGTH BIG TNOW MAINT_COST REPAIR_COST SALES_REVENUE EXP_RATE 
global A3 B3 B U L STATES_MAX MEAN_PROD_TIME

% A repair has just been scheduled

event_clock(3)=BIG; % first wipe out the time of the current event

alg.revenue=alg.revenue-REPAIR_COST;
alg.old_action=1;
[alg]=rac(alg); 
alg.prodcount=0;
alg.old_prodcount=alg.prodcount;
alg.time_for_failure=emp_rnd(alg.emp_dist);
event_clock(2)=TNOW+0.1; % schedule a new production


